<template>
	<view class="home-content">
		<image src="../../static/home/home-bg.png" mode="widthFix" class="top-img"></image>
		<CustomNav :topBgColor="topBgColor" :color="titleColor" :backColor="'#999'" :isBack="true" :custom="custom"
			:title="'曝光台'"></CustomNav>
		<view class="list-block">
			<view class="classify-tab-block menu-item">
				<view class="tab-content" style="flex-grow: 1;">
					<view class="tab-item" :class="tabActive==0?'active':''" @click="bindActive(0)" style="overflow-x: scroll;">全部</view>
					<view class="tab-item" :class="tabActive==1?'active':''" @click="bindActive(1)" style="overflow-x: scroll;">失信联合惩戒</view>
					<view class="tab-item" :class="tabActive==2?'active':''" @click="bindActive(2)" style="overflow-x: scroll;">重大违法行为公布</view>
					<view class="tab-item" :class="tabActive==3?'active':''" @click="bindActive(3)" style="overflow-x: scroll;">诚信等级评定</view>
				</view>
			</view>
			<template v-if="list.length>0">
				<view v-for="(item,index) in list" :key="item.id" class="list-item"
					@click="navigate('/pages/lighthouse/detail?id='+item.id+'&type=2')">
					<view class="title">
						<view class="value">{{item.exposureTitle}}</view>
					</view>
					<view class="time">发布日期：{{item.createTime}}</view>
				</view>
			</template>
			<view v-else-if="list.length==0&&!listConf.more" style="text-align: center;">暂无数据</view>
			<view v-if="list.length>0&&!listConf.more" style="text-align: center;">没有更多了</view>
		</view>
	</view>
</template>

<script>
	import {
		getAllApi
	} from '@/api/lighthouse.js'
	import {
		isMore,
		getCustomNavData
	} from '@/util/util.js'
	export default {
		data() {
			return {
				custom: null,
				topBgColor: 'rgba(0,0,0,0)',
				titleColor: '#fff',
				keyWords: '',
				listConf: {
					page: 1,
					limit: 10,
					more: true,
				},
				list: [],
				tabActive: 0
			}
		},
		methods: {
			navigate(url) {
				uni.navigateTo({
					url
				})
			},
			bindActive(index) {
				this.tabActive = index
				this.listConf.page = 1
				this.getList(true)
				this.keyWords = ''
			},
			search() {
				this.getList(true)
			},
			getList(refresh = false) {
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				getAllApi({
					page: this.listConf.page,
					limit: this.listConf.limit,
					exposureTitle: this.keyWords,
					type: this.tabActive
				}).then(data => {
					uni.hideLoading()
					let list = data.list || [];
					if (refresh) {
						this.list = list;
					} else {
						this.list = [...this.list, ...list]
					}
					this.listConf.more = isMore(this.listConf.page, this.listConf.limit, data.count);
				}).catch(() => {
					uni.hideLoading()
				})
			}
		},
		onReachBottom() {
			if (this.listConf.more) {
				this.listConf.page++;
				this.getList()
			}
		},
		onPageScroll(e) {
			if (e.scrollTop >= 50) {
				this.topBgColor = '#117DFF';
			} else {
				this.topBgColor = 'rgba(0,0,0,0)';
			}
		},
		onLoad() {
			this.custom = getCustomNavData();
			this.getList(true)
		}
	}
</script>

<style lang="scss" scoped>
	.home-content {
		width: 100%;
		
		.classify-tab-block {
			width: 100%;
			display: flex;
			flex-direction: row;
			justify-content: center;
			align-items: center;
			position: relative;
			margin-top: 20rpx;
		
			.tab-content {
				display: flex;
				flex-direction: row;
				overflow-x: scroll;
				.tab-item {
					padding: 10rpx 15rpx;
					flex: none;
					margin-left: 30rpx;
				}
	
			}
		
		}

		.top-img {
			width: 100%;
		}

		// .search-block {
		// 	position: relative;
		// 	width: 100%;
		// 	height: 60rpx;
		// 	padding: 0 30rpx;
		// 	display: flex;
		// 	flex-direction: row;
		// 	align-items: center;

		// 	.input-block {
		// 		width: 100%;
		// 		display: flex;
		// 		flex-direction: row;
		// 		align-items: center;
		// 		border: 1px solid #fff;
		// 		border-radius: 40rpx;
		// 		padding: 0 10rpx;
		// 		height: 60rpx;

		// 		.iconfont {
		// 			flex-grow: 0;
		// 			color: #fff;
		// 			margin: 0 10rpx;
		// 		}

		// 		input {
		// 			flex-grow: 1;
		// 			font-size: 28rpx;
		// 			color: #fff;
		// 			margin: 0 10rpx;
		// 		}
		// 	}
		// }
		.list-block {
			padding: 30rpx;
			display: flex;
			flex-direction: column;
			background: #F6F6F6;
			box-shadow: 0 0 10px 0px #e8e8e8;
			border-radius: 30rpx;
			margin: 0rpx auto;
			position: relative;
			min-height: 75vh;
			margin-top: -180rpx;

			.menu-item {
				width: 100%;
				height: 120rpx;
				background-color: #fff;
				display: flex;
				flex-direction: row;
				justify-content: space-around;
				border-radius: 20rpx;

				.tab-item {
					margin-top: 30rpx;
					height: 60rpx;
					font-size: 30rpx;
				}

				.tab-item.active {
					font-size: 34rpx;
					font-weight: bold;
					height: 60rpx;
					color: #157EFE;
					border-bottom: 6rpx solid #157EFE;
				}
			}

			.list-item {
				width: calc(100% - 60rpx);
				padding: 30rpx;
				display: flex;
				flex-direction: column;
				background: #fff;
				border-radius: 12rpx;
				margin: 0rpx auto;
				margin-top: 30rpx;

				.title {
					margin-top: 20rpx;
					display: flex;
					flex-direction: row;

					.fire {
						color: #fc5a00;
						font-size: 38rpx;
						width: 40rpx;
						height: 40rpx;
						margin-top: 2rpx;
					}

					.value {
						display: -webkit-box;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 2;
						overflow: hidden;
						font-size: 30rpx;
					}
				}

				.time {
					width: calc(100% - 80rpx);
					font-size: 26rpx;
					color: #999;
					//border-bottom: 1px solid #efefef;
					margin-top: 20rpx;
					padding-bottom: 20rpx;
				}
			}

			.list-item:last-child {
				.time {
					border: none;
				}
			}
		}
	}
</style>